import {
	serverUrl
} from '../baseUrl.js';

// #ifdef APP-PLUS

let baseUrl = serverUrl + '/app';
let baseUrlAdmin = serverUrl + '/admin';

//let baseUrlJava = 'http://58.215.235.4:9017/system';
let baseUrlJava = 'http://58.215.235.4:9019/system';
let baseUrlDk = 'http://58.215.235.4:8089/api';
// #endif
// #ifdef H5
let baseUrl = '/app';
let baseUrlAdmin = '/admin';
let baseUrlJava = '/system';
let baseUrlDk = '/jydk';
// #endif
function request(url, data, method,isAdmin,isJava, isDk, ) {
	let userToken = '';
	// uni.getStorage({
 //    key: 'userToken',
 //    success: function (res) {
	// 		userToken = res.data;
	// 	}
	// });
	// let header = {
	// 	// 'content-type': 'application/x-www-form-urlencoded',
	// 	'X-Access-Token': 'token',
	// 	'Authorization': userToken,
	// };
	  return new Promise((resolve, reject) => {
		let _baseUrl = baseUrl;
		if (isJava) {
			_baseUrl = baseUrlJava;
		}
		if (isDk) {
			_baseUrl = baseUrlDk;
		}
		if (isAdmin) {
			_baseUrl = baseUrlAdmin;
		}
	    uni.request({
	      header:{Authorization:uni.getStorageSync('token')},
	      method,
		  data,
	      url: _baseUrl + url,
		  sslVerify: false,
	      success: (res) => {
			if(res.data.code == 1001){
				uni.showToast({
					title: "您的登录状态已失效，请重新登录",
				  duration: 1000,
				  icon: "error",
						});
				uni.redirectTo({
						url: "/pages/login/index"
					})
			}else{
				resolve(res)
			}
	      },
	      fail: (res) => {
	        reject(res);
	      }
	    })
	  });
}
export default request;
